package com.stgl.service;

import com.stgl.dao.BmqkDao;
import com.stgl.dao.WhkfdbDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class WhkfdbService {
    @Autowired
    private WhkfdbDao whkfdbDao;

    @Autowired
    private BmqkDao bmqkDao;

    public List<Map<String,Object>>Search_whkfdb(Map<String,Object>gmap)
    {
        List<Map<String,Object>>list1=whkfdbDao.Search_whkfdb(gmap);
        for(int i=0;i<list1.size();i++){
            Map<String,Object>maps=list1.get(i);
            List<Map<String,Object>>list2=whkfdbDao.Search_Whksf(maps);
            List<Map<String,Object>>list3=whkfdbDao.Search_Whk_teacher(maps);
            maps.put("whksf",list2);
            maps.put("whkteas",list3);
        }
        return list1;
    }


    public Map<String,Object> del_whkfdb(Map<String,Object>gmap)
    {
        Map<String,Object>rmap=new HashMap<String,Object>();
        //先查询该辅导班是否已经有学生报名 如果有 则不能删除
        List<Map<String,Object>>list1=new ArrayList<>();
        list1=bmqkDao.Search_bmqkNow(gmap);
        if(list1.size()>0){
            rmap.put("msg","该辅导班已经有学生报名,不能删除,请联系开发人员!");
            rmap.put("result",false);
        }else{
            whkfdbDao.del_whkfdb(gmap);
            whkfdbDao.del_whksf(gmap);
            whkfdbDao.del_whk_teacher(gmap);
            rmap.put("msg","删除成功!");
            rmap.put("result",true);
        }
        return rmap;
    }



    public int InsertWhkfdb(Map<String,Object>gmap)
    {
        return whkfdbDao.InsertWhkfdb(gmap);
    }



    public int InsertWhksf(Map<String,Object>gmap)
    {
        return whkfdbDao.InsertWhksf(gmap);
    }


    public int InsertWhk_teacher(Map<String,Object>gmap)
    {
        return whkfdbDao.InsertWhk_teacher(gmap);
    }


    public int EditWhkfdb(Map<String,Object>gmap)
    {
        int i=whkfdbDao.EditWhkfdb(gmap);
        whkfdbDao.del_whksf(gmap);
        whkfdbDao.del_whk_teacher(gmap);
        return i;
    }

    public void delHistoryWhkfdb(Map<String,Object>gmap)
    {
        whkfdbDao.delHistoryWhkfdb(gmap);
    }


    public void resHistoryWhkfdb(Map<String,Object>gmap)
    {
        whkfdbDao.resHistoryWhkfdb(gmap);
    }


}
